<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>登录</h1>
<form action="">
  <input type="text" name="username" v-model="user.username" placeholder="用户名">
  <input type="text" name="password" v-model="user.password" placeholder="密码"><br>
  <input type="checkbox" name="rem" v-model="user.rem">记住用户名和密码<br>
  <input type="button" value="登录" @click="login()">
</form>
<script src="js/vue.min.js"></script>
<script src="js/axios.min.js"></script>
<script>
  let v = new Vue({
    el:"form",
    data:{
      user:{
        username:"",
        password:"",
        rem:"",
      }
    },
    methods:{
      login(){
        axios.post("/login",v.user).then(function (response){
          if(response.data==1){
            alert("登录成功");
            location.href="/";
          }else if(response.data==2){
            alert("密码错误");
            location.reload()
          }else{
            alert("用户名不存在");
            location.reload();

          }
        })
      }
    }
  })

  let cookieStr = document.cookie;
  let cookieArr = cookieStr.split(";")
  for(let cookie of cookieArr){
      let arr = cookie.split("=");
      let name = arr[0].trim();
      let values = arr[1];
      if("username"==name){
          v.user.username=values
      }else if("password"==name){
          v.user.password=values
      }
  }

</script>
</body>
</html>